package ink.onei.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ink.onei.common.annotation.Log;
import ink.onei.common.core.controller.BaseController;
import ink.onei.common.core.domain.AjaxResult;
import ink.onei.common.enums.BusinessType;
import ink.onei.system.domain.PrivateLetter;
import ink.onei.system.service.IPrivateLetterService;
import ink.onei.common.utils.poi.ExcelUtil;
import ink.onei.common.core.page.TableDataInfo;

/**
 * 私信Controller
 *
 * @author zheng
 * @date 2024-02-15
 */
@RestController
@RequestMapping("/system/letter")
public class PrivateLetterController extends BaseController {
    @Autowired
    private IPrivateLetterService privateLetterService;
    /**
     * 查询私信列表
     */
    @PreAuthorize("@ss.hasPermi('system:letter:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrivateLetter privateLetter) {
        startPage();
        List<PrivateLetter> list = privateLetterService.selectPrivateLetterList(privateLetter);
        return getDataTable(list);
    }

    /**
     * 导出私信列表
     */
    @PreAuthorize("@ss.hasPermi('system:letter:export')")
    @Log(title = "私信", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PrivateLetter privateLetter) {
        List<PrivateLetter> list = privateLetterService.selectPrivateLetterList(privateLetter);
        ExcelUtil<PrivateLetter> util = new ExcelUtil<PrivateLetter>(PrivateLetter.class);
        util.exportExcel(response, list, "私信数据");
    }

    /**
     * 获取私信详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:letter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(privateLetterService.selectPrivateLetterById(id));
    }
    /**
     * 查看私信详细信息
     */
/*
    @PreAuthorize("@ss.hasPermi('system:letter:look')")
    @GetMapping(value = "/{id}")
    public AjaxResult getLook(@PathVariable("id") Long id) {
        return success(privateLetterService.selectLetterLookById(id));
    }
*/

    /**
     * 新增私信
     */
    @PreAuthorize("@ss.hasPermi('system:letter:add')")
    @Log(title = "私信", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrivateLetter privateLetter) {
        return toAjax(privateLetterService.insertPrivateLetter(privateLetter));
    }

    /**
     * 修改私信
     */
    @PreAuthorize("@ss.hasPermi('system:letter:edit')")
    @Log(title = "私信", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrivateLetter privateLetter) {
        return toAjax(privateLetterService.updatePrivateLetter(privateLetter));
    }

    /**
     * 删除私信
     */
    @PreAuthorize("@ss.hasPermi('system:letter:remove')")
    @Log(title = "私信", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(privateLetterService.deletePrivateLetterByIds(ids));
    }
}
